package com.vmj.classfile.entity.constantinfo;

import com.vmj.classfile.ClassReader;
import com.vmj.classfile.entity.AbstractConstantInfo;
import com.vmj.common.Mutf8Decoder;

import java.io.IOException;

/**
 * Created by yangshoujun on 2017/8/6 上午11:33.
 */
public class ConstantUtf8Info extends AbstractConstantInfo {

    int length;
    String str;

    public ConstantUtf8Info(ClassReader reader) {
        super(reader);
    }

    public void parse() {
        length = getReader().readTwoByte();
        if(length > 0) {
            byte[] bytes = getReader().readByte(length);
            try {
                str = Mutf8Decoder.decodeMutf8(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

    public int getLength() {
        return length;
    }

    public String getStr() {
        return str;
    }
}
